package br.com.social.mobile.dao;

import javax.persistence.Query;

import org.apache.log4j.Logger;

import br.com.social.mobile.entities.Profile;



public class ProfileDAO extends GenericDAO<Profile>{

	private Logger logger = Logger.getLogger(ProfileDAO.class);
	
	public Profile validateLogin(String dsLogin, String dsPassword) {
		try {
			createEntityManager();
			Query query = entityManager
					.createQuery("select p FROM Profile p where p.dsLogin= :dsLogin and p.dsPassword= :dsPassword");
			query.setParameter("dsLogin", dsLogin);
			query.setParameter("dsPassword", dsPassword);

			return (Profile) query.getSingleResult();
		} catch (Exception e) {
			logger.error(e);
			return null;
		}
		
	}	
	
	public Profile getByCrsId(Integer nuCrsProfile) {
		try {
			createEntityManager();
			Query query = entityManager
					.createQuery("select p FROM Profile p where p.nuCrsProfile= :nuCrsProfile");
			query.setParameter("nuCrsProfile", nuCrsProfile);

			return (Profile) query.getSingleResult();
		} catch (Exception e) {
			logger.error(e);
			return null;
		}
		
	}
	
	public Profile getByLogin(String dsLogin) {
		try {
			createEntityManager();
			Query query = entityManager
					.createQuery("select p FROM Profile p where p.dsLogin= :dsLogin");
			query.setParameter("dsLogin", dsLogin);

			return (Profile) query.getSingleResult();
		} catch (Exception e) {
			logger.error(e);
			return null;
		}
		
	}	
 
}
